﻿/**
 * 功能:[主潜能2]
 * 
 */

var 音符 = "#fEffect/CharacterEff/1032063/0/0#";
var 新 = "#fUI/UIWindow/Quest/icon5/1#";
var 小黄点 = "#fUI/UIPVP/MiniMapIcon/yellow#";
var UI0 = "#fEffect/CharacterEff/1051296/1/0#";
var UI1 = "#fEffect/CharacterEff/1051296/1/1#";
var UI2 = "#fEffect/CharacterEff/1051296/1/2#";
var UI3 = "#fEffect/CharacterEff/1051296/1/3#";
var UI4 = "#fEffect/CharacterEff/1051296/1/4#";
var UI5 = "#fEffect/CharacterEff/1051296/1/5#";

var UI11 = "#fEffect/EventEffect/EffectAttach/3110001/emblem1/1/0#";
var UI22 = "#fEffect/EventEffect/EffectAttach/3110001/emblem2/1/0#";
var UI33 = "#fEffect/EventEffect/EffectAttach/3110001/emblem3/1/0#";
var UI44 = "#fEffect/EventEffect/EffectAttach/3110001/emblem4/1/0#";
var UI55 = "#fEffect/EventEffect/EffectAttach/3110001/emblem5/1/0#";
var UI66 = "#fEffect/EventEffect/EffectAttach/3110001/emblem6/1/0#";
var UI77 = "#fEffect/EventEffect/EffectAttach/3110001/emblem7/1/0#";
var UI88 = "#fEffect/EventEffect/EffectAttach/3110001/emblem8/1/0#";
var UI99 = "#fEffect/EventEffect/EffectAttach/3110001/emblem9/1/0#";

var 音符横条 = 音符 + 音符 + 音符 + 音符 + 音符 + 音符 + 音符;
var 蓝星横条 = UI0 + UI1 + UI2 + UI3 + UI4 + UI5 + UI0 + UI1 + UI2 + UI3 + UI4 + UI5 + UI0 + UI1 + UI2 + UI3 + UI4;
var 活跃 = "#fUI/CashShop.img/CashItem_label/2#";//"+ttt+"//美化1
var 积分 = "#fUI/CashShop.img/CashItem_label/3#";//"+ttt+"//美化1


var status = -1;
var potList = Array(
		Array(40041, "力量 +6%", 40000),
		Array(40042, "敏捷 +6%", 40000),
		Array(40043, "智力 +6%", 40000),
		Array(40044, "运气 +6%", 40000),
		Array(40051, "物攻 +6%", 40000),
		Array(40052, "魔攻 +6%", 40000),
        Array(40054, "防御 +6%", 40000),		
		Array(40055, "暴击 +6%", 40000),		
		Array(40045, "Maxhp +6%", 40000),	
		Array(40046, "Maxmp +6%", 40000),		
		Array(30106, "全技能等级 +1", 20000));

		
var potId = -1; //潜能的ID
var depict = ""; //潜能的描述
var points = -1; //每次的价格

var newEquip,oldEquip;

//定义洗到那个属性的次数
var count = 1; 

//修改的装备在背包的位置
var slot = 1; 

//修改的是第几条潜能 [1-3] 为普通 [4-6] 为附加
var potline = 4; 
var Nx = -1;


var UI = "#fUI/UIWindow.img/ToolTip/Equip/Star/Star#";


function start() {
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == 1) {
		status++;
	} else {
		if (status >= 0) {
			cm.dispose();
			return;
		}
		status--;
	}
	if (status == 0) {
		var selStr = "";
		selStr += "" + 音符横条 + "\r\n";
		selStr += "  "+积分+"您拥有活跃值：#r"+cm.getPlayerPoints() + "  "+活跃+"#k您拥有微积分:#r"+cm.getPlayerEnergy()+ "\r\n";
		selStr += "" + 音符横条 + "\r\n";
		for (var i = 0; i < potList.length; i++) {
			selStr += "\r\n#L" + i + "##b" + UI + " " + potList[i][1] + "#k  #d(需消耗:#r" + potList[i][2] + "#k #k#d PPMS活跃+PPMS微积分)#l\r\n";
		}
		cm.sendSimple(selStr + " \r\n ");
	} else if (status == 1) {
		oldEquip = cm.getEquipBySlot(slot);
		if (oldEquip == null) {
			cm.sendOk("出现错误: \r\n背包栏第1个位置的装备为空");
			cm.dispose();
			return;
		}

		if (oldEquip.getState(false) != 0x14) { 
			cm.sendOk("出现错误: 背包栏第1个位置的装备的潜能等级不是SS级");
			cm.dispose();
			return;
		}

		var pot = potList[selection];
		if (pot != null) {
			potId = pot[0];
			depict = pot[1];
			points = pot[2];
			cm.sendYesNo("您是否要将#b装备栏第一格装备\r\n第"+potline+"条潜能属性(不会改变其它潜能属性)#k\r\n一键洗潜能属性为 #b" + depict + "#k？");
		} else {
			cm.sendOk("出现错误...");
			cm.dispose();
		}
	} else if (status == 2) {
		if (cm.getPlayerPoints() < points) {
			cm.sendOk("请确认你是否有"+points+"点PPMS活跃值");
			cm.dispose();
			return;
		}
		if (cm.getPlayerEnergy() < points) {
			cm.sendOk("请确认你是否有"+points+"点PPMS微积分");
			cm.dispose();
			return;
		}
		if (potId <= 0 || depict == "" || points <= 0) {
			cm.sendOk("购买道具出现错误...");
			cm.dispose();
			return;
		}
		cm.sendYesNo("洗出潜能属性为 #b" + depict + "#k 用了 #b" + count + "#k 次。\r\n本次保留该属性需要:#r #k " + points + " PPMS活跃值还有" + points + "PPMS微积分值.是否要使用？");
	} else if (status == 3) {
		newEquip = cm.getEquipBySlot(slot);
		if (oldEquip == newEquip) { //这个地方还需要检测点卷数量
			if (cm.changePotential(slot, potline, potId, false)) { //[装备位置] [潜能位置] [潜能ID] [是否公告]
				//todo 扣点卷
				cm.gainPlayerPoints(-points);
				cm.gainPlayerEnergy(-points);
				cm.sendOk("恭喜您成功洗出潜能属性....");	
			    cm.worldSpouseMessage(0x0C, "[免费潜能]：" + cm.getChar().getName()+ " "+" 使用微积分＆活跃值重置了装备的一条潜能.");				
				cm.getPlayer().saveToDB(false, false);
				cm.dispose();
				return;
			} else {
				cm.sendOk("出现错误...");
				cm.dispose();
			}
		} else {
			cm.sendOk("出现错误...");
			cm.dispose();
		}
	}
}
